# 反转链表
class Solution:
    def reverseList(self, head: Optional[ListNode]) -> Optional[ListNode]:
        previous=None
        while head:
            current=head
            head=head.next
            current.next=previous
            previous=current
        return previous

# 链表成环
class Solution:
    def hasCycle(self, head: Optional[ListNode]) -> bool:
        if not head:
            return False
        slow,fast=head,head.next
        while slow and fast and fast.next:
            if slow == fast:
                return True
            slow=slow.next
            fast=fast.next.next
        return False
